<template>
  <div class="product-test-collection-page">
    <el-card
      class="aui-card--fill"
      shadow="never">
      <el-form
        :inline="true"
        :model="dataForm">
        <!--        <el-form-item>-->

        <!--          <product-type-select :type="dataForm.productTypeId" @change="onTypeChanged"></product-type-select>-->

        <!--        </el-form-item>-->

        <!--        <el-form-item>-->
        <!--          <el-input-->
        <!--            clearable-->
        <!--            placeholder="集合名称"-->
        <!--            v-model="dataForm.collectionName"-->
        <!--          >-->
        <!--            <el-button slot="append" @click="getDataList()">-->
        <!--              <i class="el-icon-search"></i>-->
        <!--            </el-button>-->
        <!--          </el-input>-->
        <!--        </el-form-item>-->
        <el-form-item>
          <!--           -->
          <el-button
            type="primary"
            @click="clickOnAddOrUpdate()">
            新建集合
          </el-button>
        </el-form-item>
      </el-form>

      <div class="table-container">
        <el-table
          border
          style="width: 100%"
          :data="dataList">
          <!--                    :label="$t('appData.user.table.title')"-->
          <el-table-column
            align="center"
            header-align="center"
            label="集合名称"
            prop="collectionName"
          />

          <el-table-column
            align="center"
            header-align="center"
            label="设备ID"
            prop="deviceId"
          />
          <el-table-column
            align="center"
            header-align="center"
            label="关联产品名"
            prop="productName"
          >
            <template slot-scope="scope">
              <div class="product-desc">
                <span>{{ scope.row.productName }}</span>
                <span>
                  ({{ scope.row.productType }}{{ scope.row.typeCode }})</span
                  >
              </div>
            </template>
          </el-table-column>

          <!--          <el-table-column-->
          <!--            align="center"-->
          <!--            header-align="center"-->
          <!--            label="创建时间"-->
          <!--            prop="createTime"-->
          <!--          >-->
          <!--          </el-table-column>-->

          <!--          <el-table-column-->
          <!--            :label="$t('news.content')"-->
          <!--            align="center"-->
          <!--            header-align="center"-->
          <!--            prop="taskContent"-->
          <!--          >-->
          <!--            <template slot-scope="scope">-->
          <!--              <div class="task-content" v-html="scope.row.taskContent"></div>-->
          <!--            </template>-->
          <!--          </el-table-column>-->

          <el-table-column
            :label="$t('handle')"
            align="center"
            fixed="right"
            header-align="center"
            width="300"
          >
            <template slot-scope="scope">
              <!--                                    v-if="$hasPermission('monitor:mmonitorapilist:update')"
          -->
              <el-button
                @click="clickOnAddOrUpdate(scope.row.id)"
                size="small"
                type="primary"
                plain
              >{{ $t("update") }}
              </el-button>
              <!--              v-if="$hasPermission('monitor:mmonitorapilist:delete')"-->
              <el-button
                @click="deleteHandle(scope.row.id)"
                size="small"
                type="danger"
                plain
              >{{ $t("delete") }}
              </el-button>

              <el-button
                @click="clickOnRunTest(scope.row.id)"
                size="small"
                type="success"
                plain
              >
                <i class="el-icon-refresh"/>
                <span>运行测试</span>
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="page"
          :page-size="limit"
          :page-sizes="[10, 20, 50, 100]"
          :total="total"
          @current-change="pageCurrentChangeHandle"
          @size-change="pageSizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
        />

        <test-collection-add-or-update
          @refreshDataList="getDataList"
          ref="addOrUpdate"
          v-if="addOrUpdateVisible"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import TestCollectionAddOrUpdate from './testCollection-add-or-update'
import ProductTypeSelect from '../../../components/product.type.select'
export default {
  name: 'ProductTestCollectionPage',
  components: { ProductTypeSelect, TestCollectionAddOrUpdate },
  mixins: [mixinViewModule],
  data () {
    return {
      producttypes: [],
      mixinViewModuleOptions: {
        getDataListURL: '/product/ptestcollection/page',
        getDataListIsPage: true,
        deleteURL: '/product/ptestcollection',
        deleteIsBatch: true
        // exportURL: '/sys/user/export'
      },
      dataForm: {
        productTypeId: '',
        collectionName: ''
      }
    }
  },
  methods: {
    onTypeChanged (value) {
      this.dataForm.productTypeId = value
      this.getDataList()
    },

    // handleResponseListData(data){
    //
    //   return data
    // },
    clickOnAddOrUpdate (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.form.id = id
        // this.$refs.addOrUpdate.dataForm.sn8 = this.dataForm.sn8
        this.$refs.addOrUpdate.init()
      })
    },
    clickOnRunTest (id) {
      this.$confirm(
        this.$t('prompt.info', { handle: '运行测试' }),
        this.$t('prompt.title'),
        {
          confirmButtonText: this.$t('confirm'),
          cancelButtonText: this.$t('cancel'),
          type: 'warning'
        }
      ).then(() => {
        this.$http
          .get(`/product/ptestcollection/executeCollection/${id}`)
          .then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.$message({
              message: this.$t('prompt.success'),
              type: 'success',
              duration: 500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.product-test-collection-page {
  .product-desc {
    span {
      &:last-child {
      }
    }
  }
}
</style>
